package Classes.GameDatas// ActionScript file
{
	import Classes.GameUtils.GD_deal;
	import Classes.GameUtils.GU_DataTransform;
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	
	import UIComponents.IStore;
	import UIComponents.IUseItem;
	
	import flash.display.DisplayObject;

	/**
	 *物品数据类 
	 * @author 葛增文
	 * 
	 */	
	public class GD_Item extends GameData implements IStore,IUseItem
	{
		public static var _itemConfigDatasObj:Object;
		private static const ITEMCONFIGDATAFIELDLENGTH:int=9;
		/**
		 * 物品的ID 
		 */		
		private var _itemType:Number;
		private var _configObj:Object;
		private var _itemNumber:int;
		
		private var _icon:ViewIcon;
		//物品类型
		private var _itemStyle:int;
		//控制使用按钮是否显示 
		private var _useBtnVisiable:Boolean=true;
		//private var _view:VD_Item;
		public function GD_Item(itemType:Number,itemNum:int):void
		{
			this._itemType=itemType;
			this._itemNumber=itemNum;
			this.init();
		}
		
		private function init():void
		{
			this._configObj=itemConfigDatasObj[this.itemType];
			this._itemStyle=int(this._configObj.zt_item_type);
		}
		
		/**
		 * 创建一个GD_Item 
		 * @param creatObj  建筑类型
		 * @return 
		 */		
		public static function creat(creatObj:Object):GD_Item
		{
			var itemNum:int=creatObj.itemNum?creatObj.itemNum:0;
//			var returnObj:GD_Item=new GD_Item(creatObj.itemType,itemNum);
			var returnObj:GD_Item=new GD_Item_Use(creatObj.itemType,itemNum);
			return returnObj;
		}
		
		public function creatTmpIcon():ViewIcon
		{
			return ViewIcon.creat({sourceName:this.sourceName,picName:this.picName});
		}
		
		/**
		 * 使用物品 
		 */		
		public function useItem():void
		{
		}

		override public function release():void
		{
			
		}
		
		public static function getItemConfigDataByType(itemType:Number):Object
		{
			return itemConfigDatasObj[itemType];
		}

		/*getter & setter*/
		public static function get itemConfigDatasObj():Object
		{
			if(!_itemConfigDatasObj)
			{
				_itemConfigDatasObj=new Object;
				var itemConfigDatasStr:String=M_ConfigData.instance.getCSVByName("物品配置表");
				var itemConfigDatasAry:Array=GU_DataTransform.csvTransformObjsAry(itemConfigDatasStr,ITEMCONFIGDATAFIELDLENGTH);
				for each(var itemConfigDataObj:Object in itemConfigDatasAry)
				{
					_itemConfigDatasObj[itemConfigDataObj.zt_item_id]=itemConfigDataObj;
				}
			}
			return _itemConfigDatasObj;
		}
		/**
		 * 物品id 
		 * @return 
		 */		
		public function get itemType():Number
		{
			return _itemType;
		}

		public function get configObj():Object
		{
			return _configObj;
		}

		public function get itemNumber():int
		{
			return _itemNumber;
		}
		
		public function get itemBaseType():int
		{
			return this.configObj.zt_item_type;
		}
		
		public function get itemName():String
		{
			return this.configObj.zt_item_name;
		}
		
		public function get sourceName():String
		{
			return this.configObj.zt_item_source;
		}
		
		public function get picName():String
		{
			return this.configObj.zt_item_pic;
		}
		
		public function getStoreItmePic():String
		{
			return this.configObj.zt_item_pic;
		}
		
		public function get description():String
		{
			return this.configObj.zt_item_desc;
		}
		
		public function get needLv():int
		{
			return this.configObj.zt_need_lever;
		}
		
		public function get buyType():int
		{
			return this.configObj.zt_buy_type;
		}
		
		public function get deleteType():int
		{
			return this.configObj.zt_delete_type;
		}

		public function set itemNumber(value:int):void
		{
			_itemNumber = value;
			this.touchObserve("itemNumber");
			if(this.itemId==M_ConfigData.instance.exchangeItemId)
			{
				GD_Player.instance.exchangeBuildItemNum=value;
			}
		}
		
		public function get itemPic():DisplayObject
		{
			return this.icon;
		}
		
		/**
		 * 商店接口信息 
		 * @return 
		 * 
		 */		
		public function getStoreItemIcon():DisplayObject
		{
			return creatTmpIcon();
		}
		
		/**
		 * 商店接口信息 
		 * @return 
		 * 
		 */	
		public function getStroeItemDes():String
		{
			return this.configObj.zt_item_desc;
		}
		/**
		 * 商店接口信息 
		 * @return 
		 * 
		 */	
		public function getStoreItemName():String
		{
			return this.configObj.zt_item_name;
		}
		
		public function doSomeThingFun(shopId:Number,itemPrice:Number,moneyType:Number,isDoing:Boolean=true):void{};
		
		public function get useEnabled():Boolean
		{
			if(GD_deal.instance.getStr(_itemType)==102 || GD_deal.instance.getStr(_itemType)==103 || GD_deal.instance.getStr(_itemType)==104) 
				return true;
			else
				return false;
		}

		public function get icon():ViewIcon
		{
//			if(!_icon)
//			{
				_icon=ViewIcon.creat({dataTarget:this,creatType:"item"});
				_icon.numSP.x=56;
				_icon.numSP.y=20;
				_icon.scaleX=0.9;
				_icon.scaleY=0.9;
//			}
			return _icon;
		}

		/**
		 * 物品的类型 
		 */
		public function get itemStyle():int
		{
			return _itemStyle;
		}

		/**
		 * 控制使用按钮是否显示 
		 */
		public function get useBtnVisiable():Boolean
		{
			return _useBtnVisiable;
		}
		
		public function get itemId():Number
		{
			return this._itemType;
		}


	}
}